package server;

public class Utility {

	public static final int PORT = 1337;
	
	public static String checkUrlAndReply(String serverName, String request) {
		if (request.startsWith("GET /gettimeblock HTTP")) {
			return getPage(serverName, 512);
		} else {
			return "Invalid URL";
		}
	}
	

	
	public static String getPage(String serverName, int workerID) {
		
		StringBuilder sb = new StringBuilder();
		
		sb.append("HTTP/1.1 200 OK\n");
		sb.append("Date: Sat, 07 Mar 2009 00:00:00 GMT\n");
		sb.append("Server: " + serverName + "\n");
		sb.append("Accept-Ranges: bytes\n");
		sb.append("Content-Length: $$$$\n");
		sb.append("Connection: close\n");
		sb.append("Content-Type: text/html\n");
		sb.append("\n");
		
		String header = sb.toString();
			
		String body = "<html><body><h1>Page processed by: Worker (" + workerID + ")</h1></body></html>";
		
		header = header.replace("$$$$", String.valueOf(body.length()));
		String result = header + body;
		
		return result;
	}
}
